import 'package:flutter/material.dart';

class WFAddableWidget extends StatefulWidget {

	_WFAddableWidgetState? state;

	final Widget child;

	WFAddableWidget(this.child);

	void addSubView(child,{ double top=0.0,double left=0.0,double height=0.0,double width=0.0}) {
		state?.addSubView(
			child,
			top: top,
			left: left,
			height: height,
			width: width
		);
	}


	@override
	_WFAddableWidgetState createState() {
		state = _WFAddableWidgetState();
		return state!;
	}
}

class _WFAddableWidgetState extends State<WFAddableWidget> {

	List<Widget>? children;

	@override
	void initState() {
		super.initState();
		children = [widget.child];
	}


	@override
	Widget build(BuildContext context) {
		return Stack(
			children: children!,
		);
	}

	void addSubView( child, {double top=0.0,double left=0.0,double height=0,double width=0}) {
		Positioned p = Positioned(
			child: SizedBox(
				height: height,
				width: width,
				child: child,
			),
			top: top,
			left: left,
		);
		children!.add(p);
		setState(() {});
	}
}
